package com.ruoyi.project.men.service.impl;


import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.bootdo.PageHelperUtils;
import com.ruoyi.common.utils.bootdo.R;
import com.ruoyi.common.utils.bootdo.UuidUtil;
import com.ruoyi.project.men.dao.MenNeedInfoDao;
import com.ruoyi.project.men.dao.MenNeedUserDao;
import com.ruoyi.project.men.domain.MenNeedInfoDO;
import com.ruoyi.project.men.domain.MenNeedUserDO;
import com.ruoyi.project.men.service.MenNeedUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Service
public class MenNeedUserServiceImpl implements MenNeedUserService {
	@Autowired
	private MenNeedUserDao menNeedUserDao;
	@Autowired
	private MenNeedInfoDao menNeedInfoDao;
	
	@Override
	public MenNeedUserDO get(String id){
		return menNeedUserDao.get(id);
	}
	
	@Override
	public List<MenNeedUserDO> list(Map<String, Object> map){
		return menNeedUserDao.list(map);
	}

	@Override
	public List<Map<String, Object>> userList(Map<String, Object> map){
		return menNeedUserDao.userList(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return menNeedUserDao.count(map);
	}
	
	@Override
	public int save(MenNeedUserDO menNeedUser){
		return menNeedUserDao.save(menNeedUser);
	}
	
	@Override
	public int update(MenNeedUserDO menNeedUser){
		return menNeedUserDao.update(menNeedUser);
	}
	
	@Override
	public int remove(String id){
		return menNeedUserDao.remove(id);
	}
	
	@Override
	public int batchRemove(String[] ids){
		return menNeedUserDao.batchRemove(ids);
	}

    @Override
    public List<MenNeedUserDO> likeList(Map<String, Object> map){
        return menNeedUserDao.likeList(map);
    }
    @Override
    public int likeListCount(Map<String, Object> map){
        return menNeedUserDao.likeListCount(map);
    }

    @Override
    public R receiveNeed(Map<String, Object> params) {
        MenNeedUserDO menNeedUserDO = new MenNeedUserDO();
		menNeedUserDO.setDelFlag(0);
		menNeedUserDO.setCaAt(new Date());
		menNeedUserDO.setUpAt(new Date());
		menNeedUserDO.setId(UuidUtil.get32UUID());
		menNeedUserDO.setNeedId(params.get("needId").toString());
		menNeedUserDO.setUserId(params.get("userId").toString());
		menNeedUserDao.save(menNeedUserDO);
		return R.ok(0,"领取成功");

    }

    @Override
    public R myNeedList(Map<String, Object> params) {
		if(params.get("status").toString().equals("0")){
			PageHelperUtils.page(params);
			List<Map<String,Object>> list =  menNeedUserDao.myNeedList(params);
			PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(list);
			return R.ok().put("data",pageInfo);
		}else{

			PageHelperUtils.page(params);
			List<Map<String,Object>> list =  menNeedInfoDao.myNeedList(params);
			PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(list);
			return R.ok().put("data",pageInfo);

		}



    }

    @Override
    public R deleteMyNeed(Map<String, Object> params) {
		if(params.get("status").toString().equals("0")){
			MenNeedUserDO menNeedUserDO = menNeedUserDao.get(params.get("needId").toString());
			if(menNeedUserDO!=null){
				menNeedUserDO.setDelFlag(1);
				menNeedUserDO.setUpAt(new Date());
				menNeedUserDao.update(menNeedUserDO);
				return R.ok(0,"删除成功");
			}
			return R.error("需求不存在");
		}else{
			MenNeedInfoDO menNeedInfoDO = menNeedInfoDao.get(params.get("needId").toString());
			if(menNeedInfoDO!=null){
				menNeedInfoDO.setDelFlag(1);
				menNeedInfoDO.setUpAt(new Date());
				menNeedInfoDao.update(menNeedInfoDO);
				return R.ok(0,"删除成功");
			}
			return R.error("需求不存在");

		}


    }

}
